﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class EmailCheck : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            phNotValidated.Visible = true;
            phValidated.Visible = false;
            if (Request.QueryString["code"] != null)
            {
                ClimateChangeChampionsData.DataContext context = new ClimateChangeChampionsData.DataContext();
                ClimateChangeChampionsData.Pledge pledge = ClimateChangeChampionsData.Pledge.GetByAuthenicationKey(context, Request.QueryString["code"].Trim());

                if (pledge != null)
                {
                    pledge.Authenticated = true;
                    context.SubmitChanges();

                    phNotValidated.Visible = false;
                    phValidated.Visible = true;

                    lblDisplayName.Text = pledge.DisplayName;

                    ClimateChangeChampionsData.UserCustomProperty tmpSchoolNameProp = (from schoolName in context.UserCustomProperties where schoolName.Name == "School Name" && schoolName.UserId == pledge.UserId select schoolName).FirstOrDefault();
                    if (tmpSchoolNameProp != null)
                    {
                        lblSchoolName.Text = tmpSchoolNameProp.Value;
                    }
                }
            }
        }

    }
}
